package com.tjl.yangxixis.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.lyp.jsonbean.LoginBean;
import com.lyp.jsonbean.PersonageBean;
import com.tjl.yangxixis.R;
import com.tjl.yangxixis.api.YangxixiApi;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 *
 * @author Administrator
 * 销售经理的个人中心
 */
public class PersonageMessageActivity extends Activity implements OnClickListener{

	private ImageView mBack;
	private List<PersonageBean.DataBean> mList = new ArrayList<>();
	private LoginBean.DataBean bean;
	private Button mExit;
	private LinearLayout mNoalter,mVerify;
	private TextView mMessage,mMendian,mZhiwei;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.item_message);
		initview();
	}



	private void initview(){
		bean = (LoginBean.DataBean) getIntent().getExtras().get("databean");
		mNoalter = (LinearLayout) findViewById(R.id.ll_pserson_noalter);
		mVerify = (LinearLayout) findViewById(R.id.ll_pserson_verify);
		mBack = (ImageView) findViewById(R.id.iv_message_back);
		mMessage = (TextView) findViewById(R.id.iv_pserson_number);
		mMendian = (TextView) findViewById(R.id.iv_pserson_mendian);
		mZhiwei = (TextView) findViewById(R.id.iv_pserson_zhiwei);
//		mExit = (Button) findViewById(R.id.btn_exit);
//		mExit.setVisibility(View.VISIBLE);
		mBack.setOnClickListener(this);
		mNoalter.setOnClickListener(this);
		mVerify.setOnClickListener(this);
//		mExit.setOnClickListener(this);

		Person(bean.getId());
	}

	//个人信息
	public void Person(String a_id) {
		Retrofit retrofit = new Retrofit.Builder()
				.baseUrl(YangxixiApi.APP_URL)
				.addConverterFactory(GsonConverterFactory.create())
				.build();

		YangxixiApi api = retrofit.create(YangxixiApi.class);
		Call<PersonageBean> call = api.getPerson(a_id);
		call.enqueue(new Callback<PersonageBean>() {
			@Override
			public void onResponse(Call<PersonageBean> call, final Response<PersonageBean> response) {
				if (response.body().getResult() == 1 ) {
					PersonageMessageActivity.this.runOnUiThread(new Runnable() {
						@Override
						public void run() {
							mList.addAll(response.body().getData());
							mMessage.setText(mList.get(0).getUser());
							mMendian.setText(mList.get(0).getCompany_name());
							if (mList.get(0).getManager().equals("0")){
								mZhiwei.setText("施工人员");
							}else {
								mZhiwei.setText("经理");
							}
						}
					});
				}
			}
			@Override
			public void onFailure(Call<PersonageBean> call, Throwable t) {
				ToastUtils.showShort(t.getMessage());
			}
		});
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (arg0.getId()) {
			case R.id.iv_message_back:
				finish();//返回上个界面
				break;
			//密码设置
			case R.id.ll_pserson_noalter:
				intent = new Intent(this,UpdatePwdActivity.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("databean",bean);
				intent.putExtras(bundle);
				startActivity(intent);
				break;
			//员工管理
			case R.id.ll_pserson_verify:
				intent = new Intent(this,ResetPwdActivity.class);
				Bundle bundles = new Bundle();
				bundles.putSerializable("databean",bean);
				intent.putExtras(bundles);
				startActivity(intent);
				break;
//			//安全退出
//			case R.id.btn_exit:
//				ToastUtils.showShort("安全退出");
////				intent = new Intent(this,LoggingActivity.class);
////				startActivity(intent);
//				break;
		}
	}


}
